<?php
if(!defined('ADMIN')){
	exit('Access Denied');
}

if($_POST['sub']!=''){

    $id=empty($_POST['id'])?0:(int)$_POST['id'];
	unset($_POST['id']);
	unset($_POST['sub']);
	$data=array('title'=>$_POST['title'],"spaceid"=>intval($_POST["spaceid"]),"starttime"=>trim($_POST["starttime"]),"endtime"=>trim($_POST["endtime"]),"disabled"=>intval($_POST["disabled"]),
    "picurl"=>trim($_POST["attachment_fileName"]),
    "adcode"=>trim($_POST["adcode"]),
    "url"=>trim($_POST["url"]),
    "addtime"=>time(),
    "uid"=>$_SESSION['EZ_Admin']['id'],    
    "username"=>$_SESSION['EZ_Admin']['name']
    );
    if(trim($_POST['title'])==""){
        jumpajax('300','广告名称不能为空','');
    }

   
 	if($id==0){

             	  
	    $id=$ezhand->insert("adv",$data);
        if($id>0){
                $uinfo =array ('f' => 'items','e' => '+','v' =>1);
                $ezhand->update("advtype",$uinfo,'id="'.$data["spaceid"].'"');
        }
        
		jumpajax('200','保存成功','','closeCurrent');
	}
	else{
	    $ezhand->update("adv",$data,'id="'.$id.'"');
		jumpajax('200','修改成功','','closeCurrent');
	}
}
else{
	$id=empty($_GET['id'])?0:(int)$_GET['id'];
	$plist=$ezhand->select_all("advtype","id,title,type,width,height");
    $poslist=array();
    while(list($k,$r)=each($plist)){
        
        $poslist[$r["id"]]=$r["title"]."[".$adspacelist[$r["type"]].":".$r["width"]."*".$r["height"]."]";
    }
    
    
    if($id==0){
	    $row=array();
	}
	else{
	    $row=$ezhand->select("adv",'*','id="'.$id.'"');
	}
}
?>